<?php
 require_once('conn.php'); 
 header("Content-type:text/html;charset=utf-8");  
 $sid = isset($_GET["sid"]) ? $_GET["sid"] : "";
 if(empty($sid) || !is_numeric($sid)){
	 mysql_close($conn); 
	 echo "document.write(\"<div align='center'><font color='red' size='+3'>主题不能为空且只能是数字</font></div>\");";
//	 echo "<div align='center'><font color='red'>主题不能为空且只能是数字</font></div>";
	 exit();
 }else{	 
	 $query = mysql_query("select * from xh_subject where id=".$sid,$conn);
	 if($row=mysql_fetch_array($query)){
		 if(date("Y-m-d H:i:s",mkDate($row["qx"]))<date("Y-m-d H:i:s")){
			 mysql_close($conn);
			 echo "document.write(\"<div align='center'><font color='red' size='+3'>主题已到期!</font></div>\");";
//			 echo "<div align='center'><font color='red'>主题已到期!</font></div>";
			 exit();
		 }
	 }else{
		 mysql_close($conn);
		 echo "document.write(\"<div align='center'><font color='red' size='+3'>该主题不存在或已被删除</font></div>\");";
//		 echo "<div align='center'><font color='red'>该主题不存在或已被删除</font></div>";
		 exit();
	 }
 }
 $getuserinfo=$cfg->getuserinfo();
 if($getuserinfo==1)
 {
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"script language='javascript' type='text/javascript'>\");\r\n";
	 echo "document.write(\" function checkVote()\");\r\n";
	 echo "document.write(\" {\");\r\n";
	 echo "document.write(\"   if(frmxhvote.username.value=='')\");\r\n";
	 echo "document.write(\"   {\");\r\n";
	 echo "document.write(\"      document.getElementById('lblusername').innerHTML='<font color=red>用户名不能为空</font>';\");\r\n";
	 echo "document.write(\"      frmxhvote.username.focus();\");\r\n";
	 echo "document.write(\"      return false;\");\r\n";
	 echo "document.write(\"   }else\");\r\n";
	 echo "document.write(\"   {\");\r\n";
	 echo "document.write(\"      document.getElementById('lblusername').innerHTML='';\");\r\n";
	 echo "document.write(\"   }\");\r\n";
	 echo "document.write(\"   if(frmxhvote.idcard.value=='')\");\r\n";
	 echo "document.write(\"   {\");\r\n";
	 echo "document.write(\"      document.getElementById('lblidcard').innerHTML='<font color=red>身份证号不能为空</font>';\");\r\n";
	 echo "document.write(\"      frmxhvote.idcard.focus();\");\r\n";
	 echo "document.write(\"      return false;\");\r\n";
	 echo "document.write(\"   }else\");\r\n";
	 echo "document.write(\"   {\");\r\n";
	 echo "document.write(\"      document.getElementById('lblidcard').innerHTML='';\");\r\n";
	 echo "document.write(\"   }\");\r\n";
	 echo "document.write(\"   if(frmxhvote.email.value=='')\");\r\n";
	 echo "document.write(\"   {\");\r\n";
	 echo "document.write(\"      document.getElementById('lblemail').innerHTML='<font color=red>邮箱地址不能为空</font>';\");\r\n";
	 echo "document.write(\"      frmxhvote.email.focus();\");\r\n";
	 echo "document.write(\"      return false;\");\r\n";
	 echo "document.write(\"   }else\");\r\n";
	 echo "document.write(\"   {\");\r\n";
	 echo "document.write(\"      document.getElementById('lblemail').innerHTML='';\");\r\n";
	 echo "document.write(\"   }\");\r\n";
	 echo "document.write(\"   return true;\");\r\n";
	 echo "document.write(\" }\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/script>\");\r\n";
 }
 
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"div width='90%' align='center'>\");\r\n";

 if($getuserinfo==1)
 {
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"form name='frmxhvote' id='frmxhvote' method='post' action='".$cfg->getsystemurl()."view.php?sid=".$sid."&act=vote' onsubmit='return checkVote();'>\");\r\n";
 }
 else
 {
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"form name='frmxhvote' id='frmxhvote' method='post' action='".$cfg->getsystemurl()."view.php?sid=".$sid."&act=vote'>\");\r\n";
 }
 
 $query = mysql_query("select * from xh_title where sid=".$sid." order by id asc",$conn);
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"div align='center'>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"table cellspacing='1' cellpadding='3'>\");\r\n";
 while($row=mysql_fetch_array($query))
 {	 
	 //在行中写下标题
	 echo "document.write(\"<br/>\");\r\n";
	 
	 
	 
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='center' colspan='".$row["listrows"]."' nowrap><font size='+3'>".$row["title"]."</font>\");\r\n";
	 echo "document.write(\"<br>\");\r\n";
	 echo "document.write(\"<br>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";
	 
	

	 
	 $qry = mysql_query("select * from xh_question where tid=".$row["id"]." order by id asc",$conn);
	 $recordcount = max(mysql_num_rows($qry),0);
	 $i=0;
	 while($qrow=mysql_fetch_array($qry))
	 {
		 if(($i%$row["listrows"])==0)
		 {
			 if($i==0)//第一行写下行标头
			 {
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"tr>\");\r\n";
			 }
			 else
			 {
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"/tr>\");\r\n";
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"tr>\");\r\n";
			 }
		 }
		 if($row["ms"]==1 && $row["listtype"]==0)
		 {//ms=1 为单选 ms=2 为多选 listtype=0 为文字 listtype=1为图片
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"td align='left'>\");\r\n";
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"input type='radio' id='".$qrow["id"]."' name='".$row["id"]."[]' value='".$qrow["id"]."'/>\");\r\n";
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
			 	 echo "document.write(\"a href='".$qrow["linkurl"]."' target='_blank'>\");\r\n";
			 }
			 
			 echo "document.write(\"".$qrow["question"]."\");\r\n";
			 
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"/a>\");\r\n";
			 }
			 
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"/td>\");\r\n";
		 }else if($row["ms"]==2 && $row["listtype"]==0)
		 {
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"td align='left'>\");\r\n";
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"input type='checkbox' id='".$qrow["id"]."' name='".$row["id"]."[]' value='".$qrow["id"]."'/>\");\r\n";
	
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
			 	 echo "document.write(\"a href='".$qrow["linkurl"]."' target='_blank'>\");\r\n";
			 }
	         echo "document.write(\"".$qrow["question"]."\");\r\n";
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"/a>\");\r\n";
			 }
			 
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"/td>\");\r\n";
		 }else if($row["ms"]=1 && $row["listtype"]==1)
		 {
			
			
			
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"td align='left'>\");\r\n";
			 
			 echo "document.write(\"<div style='margin:2em;'>\");\r\n";
			 
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
			 	 echo "document.write(\"a href='".$qrow["linkurl"]."' target='_blank'>\");\r\n";
			 }
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"img width='160' height='120' border='0' src='".$cfg->getsystemurl().$qrow["imgurl"]."' alt='".$qrow["question"]."'/>\");\r\n";
			 //test begin
			 
			 //echo "document.write(\"<div class=‘describe’ style='width:160px; height:50px;'>描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述</div>\");\r\n";
			 
			 if(strlen($qrow["jieshao"])>0){
				 echo "document.write(\"<div class=‘describe’ style='width:160px; height:50px;'>\");\r\n";
			 	 echo "document.write(\"".$qrow["jieshao"]."\");\r\n";
				 echo "document.write(\"</div>\");\r\n";
			 }
			 
			 
			   echo "document.write(\"<div align= 'center' >\");\r\n";
			 
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"input type='radio' id='".$qrow["id"]."' name='".$row["id"]."[]' value='".$qrow["id"]."'/>\");\r\n";
			 
			 echo "document.write(\"".$qrow["question"]."\");\r\n";
			 
			 
			 
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"/a>\");\r\n";
				 
			 }
			 
			   
			   
			 
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"/td>\");\r\n";
			 
			 echo "document.write(\"</div>\");\r\n";
			 echo "document.write(\"</div>\");\r\n";
			 
		 }else
		 {
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"td align='left'>\");\r\n";
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"input type='checkbox' id='".$qrow["id"]."' name='".$row["id"]."[]' value='".$qrow["id"]."'/>\");\r\n";
			 if(strlen($qrow["linkurl"])>0){
				 echo "document.write(\"<\");\r\n";
			 	 echo "document.write(\"a href='".$qrow["linkurl"]."' target='_blank'>\");\r\n";
			 }
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"img width='120' height='120' border='0' src='".$cfg->getsystemurl().$qrow["imgurl"]."' alt='".$qrow["question"]."'/>\");\r\n";
			 if(strlen($qrow["linkurl"])>0){
			 	 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"/a>\");\r\n";
			 }
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"/td>\");\r\n";
		 }
		 /*echo "document.write(\"<script language='javascript'>alert('".$i.$row["listrows"].$recordcount."')</script>\");\r\n";*/
		 if($i==$recordcount)
		 {
			 /*补齐td标签
			 echo "document.write(\"<script language='javascript'>alert('".$i%$row["listrows"].$recordcount."')</script>\");\r\n";*/
			 for($start=($i%$row["listrows"]);$start<($row["listrows"]-1);$start++)
			 {
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"td>\");\r\n";
				 echo "document.write(\"<\");\r\n";
				 echo "document.write(\"/td>\");\r\n";
			 }
			 echo "document.write(\"<\");\r\n";
			 echo "document.write(\"/tr>\");\r\n";
		 }
		 $i++;
		 
	 }
	 
 }
 mysql_free_result($query); 
 
 if($getuserinfo==1)
 {
	 //是否收集用户信息 0否 1是
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"div align='center'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"table border='0' cellspacing='1' cellpadding='3'>\");\r\n";
	 
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
     echo "document.write(\"<\");\r\n";

	 echo "document.write(\"td align='right'>姓名\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td  align='left'>\");\r\n";
     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"input type='text' name='username' id='username'/>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"label id='lblusername'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/label>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";

	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='right'>性别\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td  align='left'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"select name='sex' id='sex' size='1'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"option value='男'>男\");\r\n";
	 echo "document.write(\"<\");\r\n";
     echo "document.write(\"/option>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"option value='女'>女\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/option>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/select>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";


     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='right'>身份证号码\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td  align='left'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"input type='text' name='idcard' id='idcard'/>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"label id='lblidcard'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/label>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";

	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='right'>电话\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='left'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"input type='text' name='tel' id='tel'/>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td\");\r\n";
     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";

     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='right'>地址\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='left'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"input type='text' name='address' id='address'/>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td\");\r\n";
     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";

	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='right'>邮箱\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='left'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"input type='text' name='email' id='email'/>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"label id='lblemail'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/label>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td\");\r\n";
     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";

	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"tr>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='right'>备注\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"td align='left'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"textarea id='remarks' name='remarks' rows='5' cols='20'>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/textarea>\");\r\n";
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/td\");\r\n";
     echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/tr>\");\r\n";
	 
	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/table>\");\r\n";

	 echo "document.write(\"<\");\r\n";
	 echo "document.write(\"/div>\");\r\n";
 }
 
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"div align='center'>\");\r\n";

 echo "document.write(\"<\");\r\n";
 echo "document.write(\"table border='0' cellspacing='1' cellpadding='3' width='200'>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"tr>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"td>\");\r\n";
 echo "document.write(\"<br>\");\r\n";
  echo "document.write(\"<div align= 'center' >\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"input type='submit' name='submit' id='submit' value='投票'/>&nbsp;\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"input type='button' name='viewvote' id='viewvote' onclick=javascript:window.open('".$cfg->getsystemurl()."view.php?sid=".$sid."'); value='查看'/>&nbsp;\");\r\n"; 
  echo "document.write(\"</div>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/td>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/tr>\");\r\n";
  
 
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/table>\");\r\n";
 
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/div>\");\r\n";
 
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"div align='center'>\");\r\n";
 echo "document.write(\"<br>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"a href='".$cfg->getweburl()."' taget='_blank'>".$cfg->getwebname()."\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/a>\");\r\n";
 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/div>\");\r\n";

 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/form>\");\r\n";

 echo "document.write(\"<\");\r\n";
 echo "document.write(\"/div>\");\r\n";
 mysql_close($conn);
?>
